/*   time:2019-06-13 20:39:24*/
var e = getApp(),
    t = require("./../../../utils/core.js");
Page({
    data: {
        close: 0,
        text: "",
        imgUrl: ""
    },
    onLoad: function(t) {
        this.setData({
            close: t.close,
            text: t.text,
            imgUrl: e.globalData.approot
        })
    },
    onShow: function() {
        var t = e.getCache("sysset").shopname;
        wx.setNavigationBarTitle({
            title: t || "提示"
        })
    },
    bind: function() {
        var n = this,
            a = setInterval(function() {
                wx.getSetting({
                    success: function(e) {
                        var t = e.authSetting["scope.userInfo"];
                        t && (wx.reLaunch({
                            url: "/pages/index/index"
                        }), clearInterval(a), n.setData({
                            userInfo: t
                        }))
                    }
                })
            }, 1e3)
    },
    bindGetUserInfo: function(a) {
        var n = e.getCache("routeData"),
            i = n.url,
            s = n.params,
            o = "";
        Object.keys(s).forEach(function(e) {
            o += e + "=" + s[e] + "&"
        });
        var c = "/" + i + "?" + (s = o.substring(0, o.length - 1));
        wx.login({
            success: function(n) {
                t.post("wxapp/login", {
                    code: n.code
                }, function(n) {
                    n.error ? t.alert("获取用户登录态失败:" + n.message) : t.get("wxapp/auth", {
                        data: a.detail.encryptedData,
                        iv: a.detail.iv,
                        sessionKey: n.session_key
                    }, function(t) {
                        1 == t.isblack && wx.showModal({
                            title: "无法访问",
                            content: "您在商城的黑名单中，无权访问！",
                            success: function(t) {
                                t.confirm && e.close(), t.cancel && e.close()
                            }
                        }), a.detail.userInfo.openid = t.openId, a.detail.userInfo.id = t.id, a.detail.userInfo.uniacid = t.uniacid, e.setCache("userinfo", a.detail.userInfo), e.setCache("userinfo_openid", a.detail.userInfo.openid), e.setCache("userinfo_id", t.id), e.getSet(), wx.reLaunch({
                            url: c
                        })
                    })
                })
            },
            fail: function() {
                t.alert("获取用户信息失败!")
            }
        })
    }
});